<template>
  <van-pull-refresh class="list" v-model="listInfo.pageInfo.refreshing" @refresh="onRefresh">
    <van-list
      v-model="listInfo.pageInfo.loading"
      finished-text="没有更多了"
      :immediate-check="listInfo.isInitList"
      :finished="listInfo.pageInfo.finished"
      @load="onLoad"
    >
      <qt-card
        :list="listInfo.list"
        :toParth="listInfo.toParth"
        :cardModel="listInfo.cardModel"
        :urlParams="listInfo.urlParams"
        @click="clickCard"
      />
    </van-list>
  </van-pull-refresh>
</template>

<script>
import QtCard from '../card';

export default {
  name: 'qtList',

  components: {
    QtCard,
  },

  props: {
    listInfo: {
      type: Object,
      default() {
        return {};
      },
    },
  },

  data() {
    return {
      loadType: 'reload',
    };
  },

  methods: {
    onLoad() {
      if (this.loadType === 'reload') {
        this.loadType = '';
        this.$emit('get-list', 'reload');
      } else {
        this.listInfo.pageInfo.finished = true;
      }
    },

    onRefresh() {
      this.listInfo.pageInfo.finished = false;
      this.listInfo.pageInfo.loading = true;
      this.$emit('get-list', 'reload');
    },

    clickCard(data) {
      this.$parent.clickCard(data);
    },
  },
};
</script>
